package com.yoyo.yoyoplat.sdk;

import android.content.Context;

import com.yoyo.yoyoplat.base.ApiConstants;
import com.yoyo.yoyoplat.util.IpUtils;
import com.yoyo.yoyoplat.util.SpUtil;
import com.yoyo.yoyoplat.util.StringUtils;

public class YYSdk {
    private static YYSdk instance;

    public static YYSdk getInstance() {
        if (instance == null) {
            synchronized (YYSdk.class) {
                if (instance == null) {
                    instance = new YYSdk();
                }
            }
        }
        return instance;
    }

    /**
     * 初始化数据
     */
    public void init(Context context) {
        SpUtil.init(context);
        if (StringUtils.isNull(ApiConstants.Real_IP)) {
            String realIpAddress = SpUtil.getRealIpAddress();
            if (StringUtils.isNull(realIpAddress)) {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        ApiConstants.Real_IP = IpUtils.getNetIp();
                        SpUtil.setRealIpAddress(ApiConstants.Real_IP, 120);
                    }
                }).start();
            } else {
                ApiConstants.Real_IP = realIpAddress;
            }
        }
    }
}
